package cn.edu.gsau.info.controller;


import cn.edu.gsau.info.models.Code;
import cn.edu.gsau.info.models.ResponseResult;
import cn.edu.gsau.info.models.Zhidaojingsai;
import cn.edu.gsau.info.service.IZhidaojingsaiService;
import cn.edu.gsau.info.vo.JinsaiRules;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jinjiang
 * @since 2022-11-17
 */


/**
 * @BelongsProject: gsau_zhidaojingsai 模块
 * @BelongsPackage: cn.edu.gsau.info.controller
 * @Author: zwh
 * @CreateTime: 2022-11-21  16:44
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/zhidaojingsai")
public class ZhidaojingsaiController {

    @Value("${gsau.upload.path}")
    private String path;

    @Autowired
    IZhidaojingsaiService zhidaojingsaiService;


    /**
     * @description: 逻辑删除
     * @author: zwh
     * @date:  11 22
     * @param:
     * @return:
     * @Description: 完成
     **/
    @DeleteMapping("/delete/{id}")
    public ResponseResult<Object> delete(@RequestBody @PathVariable Long id){
        System.out.println(id);
        boolean delete = zhidaojingsaiService.delete(id);
        return new ResponseResult<Object>(Code.DELETE_OK,"成功",delete);
    }


    /**
     * @description: 修改信息
     * @author: zwh
     * @date:  11 22
     * @param:
     * @return:
     **/
    @PutMapping("/update")
    public ResponseResult<Object> update(@RequestBody Zhidaojingsai zhidaojingsai){
        boolean update = zhidaojingsaiService.update(zhidaojingsai);
        return  new ResponseResult<Object>(Code.UPDATE_OK,"成功",update);
    }



    /**
     * @description: 根据rules分页查询
     * @author: zwh
     * @date:  11 22
     * @param:
     * @return:
     **/
    @PostMapping("/rules")
    public ResponseResult selectByRules(@RequestBody JinsaiRules rules){
        IPage<Zhidaojingsai> page= zhidaojingsaiService.selectRules(rules);
        return new ResponseResult(Code.SAVE_OK,"成功",page);
    }

    /**
     * @description: 增加指导竞赛登记表
     * @author: zwh
     * @date:11 21
     * @param:
     * @return:
     **/
    @PostMapping("add")
    public ResponseResult add( @RequestBody Zhidaojingsai zhidaojingsai){

        boolean save1 = zhidaojingsaiService.save(zhidaojingsai);
        if(save1==true){
            return new ResponseResult(Code.SAVE_OK,"成功","");
        }
        else{
            return new ResponseResult(Code.SAVE_ERR,"失败","");
        }
    }




    /**
     * @description: 通过id查询指导竞赛等级表
     * @author: zwh
     * @date: 11 21
     * @param:
     * @return:
     **/
    @GetMapping("/find/{id}")
    public ResponseResult findById(@PathVariable Long id){
        Zhidaojingsai byId = zhidaojingsaiService.getById(id);
        return  new ResponseResult<Zhidaojingsai>(Code.GET_OK,"成功",byId);
    }

    /**
     * @description: 审核控制器
     * @author: zwh
     * @date:  11 28
     * @param:
     * @return:
     **/
    @PostMapping("/shenhe")
    public ResponseResult shenhe(@RequestBody Zhidaojingsai zhidaojingsai){
        zhidaojingsaiService.check(zhidaojingsai);
        return new ResponseResult<Object>(Code.SAVE_OK,"成功","");
    }


}

